'Animals IR Submission
Option Strict Off
imports System
imports PHSRAG.Insight21.Humans
imports PHSRAG.Insight21.BusinessObjects
imports FormsManagement = PHSRAG.Insight21.FormsManagement
imports System.Collections
imports CDS = PHSRAG.Insight21.CDS

module Script
    sub Main()
    
        ' cast RexParams to an AnimalsRexParams.
		
        Dim questionnaireAnswers As new ArrayList()
        Dim qV As FormsManagement.QuestionnaireVersion
        Dim questionnaireAnswer As FormsManagement.QuestionnaireAnswer
        
        if not rexParams.IsAmendment then
		    'IACUC is a required board        
            Dim iacucBoardReview as AnimalsRexParams.BoardReview = new AnimalsRexParams.BoardReview
            rexParams.BoardReviews.Add (iacucBoardReview)
            iacucBoardReview.Period = 1
            iacucBoardReview.DocumentType = "Initial Review"
            iacucBoardReview.MailGroupId = 8 'IACUC MailGroupId
            iacucBoardReview.ReviewType = ""
            iacucBoardReview.BoardStatus = "Pending"
            iacucBoardReview.OverallStatus = "Pending IACUC"
            iacucBoardReview.CurrentStatus = true
            iacucBoardReview.Note = ""
            iacucBoardReview.RTFNote = ""
            iacucBoardReview.StaffNote = ""
            iacucBoardReview.StaffNoteRTF = ""
            
            if currentProcess.Protocol.TissueTest then
                Dim tissueBoardReview as AnimalsRexParams.BoardReview = new AnimalsRexParams.BoardReview
                rexParams.BoardReviews.Add (tissueBoardReview)
                tissueBoardReview.Period = 1
                tissueBoardReview.DocumentType = "Initial Review"
                tissueBoardReview.MailGroupId = 172 'Tissue
                tissueBoardReview.ReviewType = ""
                tissueBoardReview.BoardStatus = "Pending"
                tissueBoardReview.OverallStatus = "Pending IACUC, Tissue"
                tissueBoardReview.CurrentStatus = true
                tissueBoardReview.Note = ""
                tissueBoardReview.RTFNote = ""
                tissueBoardReview.StaffNote = ""
                tissueBoardReview.StaffNoteRTF = ""
            end if
        end if
		dim overallStatus as string = "Pending IACUC"
		questionnaireAnswers= currentProtVersion.QuestionnaireAnswers
		For Each questionnaireAnswer In questionnaireAnswers
			
			qV  = questionnaireAnswer.QuestionnaireVersion
			
			''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'  STANDARD APPLICATION
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
			If (qV.Questionnaire.Name = "Standard Application") Then
				Dim answers as new ArrayList()
				answers = questionnaireAnswer.GetAnswers("Resubmission")
				If (answers.Count > 0) Then
	                	Dim resub as FormsManagement.Answer = answers(0)
				    if resub.Value = "Y" then
					    rexParams.Resubmission = true
				    else	
					    rexParams.Resubmission = false
				    end if
				End If
				
				answers = questionnaireAnswer.GetAnswers("PreviousProtocol")
				If (answers.Count > 0) Then
				    Dim prevProt as FormsManagement.Answer = answers(0)
				    Dim val as string = prevProt.Value
				    rexParams.PreviousFolderNumber = Left(val, 13)
				End If
				
				AddArrayListItem( questionnaireAnswer, "Ascites", "ASCITES", rexParams.Considerations, "Ascites production" )
				AddArrayListItem( questionnaireAnswer, "Tumor", "TUMOR", rexParams.Considerations, "Tumor growth" )
				AddArrayListItem( questionnaireAnswer, "LD50", "LD50", rexParams.Considerations, "Death as an endpoint (i.e. LD50)" )
				AddArrayListItem( questionnaireAnswer, "Burns", "BURNS", rexParams.Considerations, "Burns or trauma" )
				AddArrayListItem( questionnaireAnswer, "Device", "DEVICE", rexParams.Considerations, "Device evaluation" )
				AddArrayListItem( questionnaireAnswer, "Tran", "TRAN", rexParams.Considerations, "Transportation between non-MGH facilities" )
				AddArrayListItem( questionnaireAnswer, "IntraTran", "INTRATRAN", rexParams.Considerations, "Transportation between MGH facilities" )
				AddArrayListItem( questionnaireAnswer, "OffSiteHousing", "NONMGH", rexParams.Considerations, "Housing at non-MGH facilities" )
				AddArrayListItem( questionnaireAnswer, "Surgery", "Sx", rexParams.Considerations, "Survival Surgery" )
				AddArrayListItem( questionnaireAnswer, "SxProcedures", "MxSx", rexParams.Considerations, "Multiple survival operative procedures" )
				AddArrayListItem( questionnaireAnswer, "Paralytic", "PARALYTICS", rexParams.Considerations, "Paralytic agents" )
				AddArrayListItem( questionnaireAnswer, "Fluid", "FLUID", rexParams.Considerations, "Food or water deprivation" )
				AddArrayListItem( questionnaireAnswer, "PainStudy", "PAIN", rexParams.Considerations, "Study of pain or stress" )
				AddArrayListItem( questionnaireAnswer, "UnPain", "UNPAIN", rexParams.Considerations, "Unalleviated pain or distress" )
				AddArrayListItem( questionnaireAnswer, "Breed", "BREED", rexParams.Considerations, "Breeding Colony" )
			
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Housing
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	  
            Else If (qv.Questionnaire.Name = "Housing") Then
            
				Dim answers as new ArrayList()
				answers = questionnaireAnswer.GetAnswers("Breed")
				If (answers.Count > 0) Then
                    Dim breed as FormsManagement.Answer = answers(0)
                    if breed.Value = "BREED" then
                        rexParams.Considerations.Add("Breeding Colony")
                    end if
				End If

				answers = questionnaireAnswer.GetAnswers("Immuno")
				If (answers.Count > 0) Then
	                	Dim husbImmune as FormsManagement.Answer = answers(0)
				    if husbImmune.Value = "IMMUNO" then
					    rexParams.specialHandling.Add("ImmunoSuppresed")
				    end if
				End If

				answers = questionnaireAnswer.GetAnswers("GMA")
				If (answers.Count > 0) Then
	               		 Dim husbandGenetic as FormsManagement.Answer = answers(0)
				    if husbandGenetic.Value = "GMA" then
					    rexParams.specialHandling.Add("Transgenic")
				    end if
				End If
				
				answers = questionnaireAnswer.GetAnswers("OTR")
				If (answers.Count > 0) Then
	               		 Dim husbandGenetic as FormsManagement.Answer = answers(0)
				    if husbandGenetic.Value = "OTR" then
					    rexParams.specialHandling.Add("Knock-outs")
				    end if
				End If

				answers = questionnaireAnswer.GetAnswers("Housing")
				If (answers.Count > 0) Then
				    Dim housingAnswer As FormsManagement.Answer
					For Each housingAnswer In answers
						if  housingAnswer.Value = "114CNY1"  Then
						    rexParams.HousingLocation.Add ( "114" )	
						else if  housingAnswer.Value = "149CNY8"  Then
						    rexParams.HousingLocation.Add ( "149-8" )	
						else if  housingAnswer.Value = "149CNY9"  Then
						    rexParams.HousingLocation.Add ( "149-9" )	
						else if  housingAnswer.Value = "65LANDS"  Then
						    rexParams.HousingLocation.Add ( "(Other)" )    						    
                            ' also add in the other description.
                            	rexParams.HousingLocationOther = "65 Landsdowne"
						else if  housingAnswer.Value = "COX7"  Then
						    rexParams.HousingLocation.Add ( "COX-7" )	
						else if  housingAnswer.Value = "EDWARDS6"  Then
						    rexParams.HousingLocation.Add ( "EDR-6" )	
						else if  housingAnswer.Value = "SHRINERS"  Then
						    rexParams.HousingLocation.Add ( "SBI" )	
						else if  housingAnswer.Value = "SIMCHES8"  Then
						    rexParams.HousingLocation.Add ( "CPZ-8" )
						else if  housingAnswer.Value = "THIER8"  Then
						    rexParams.HousingLocation.Add ( "Thier-8" )	
						else if  housingAnswer.Value = "THIERB1"  Then
						    rexParams.HousingLocation.Add ( "Thier-B" )
						else if  housingAnswer.Value = "WHITE5"  Then
						    rexParams.HousingLocation.Add ( "WHT-5" )
						else if  housingAnswer.Value = "75CNY"  Then
						    rexParams.HousingLocation.Add ( "75" )
						else if  housingAnswer.Value = "114CNY1"  Then
						    rexParams.HousingLocation.Add ( "114" )
						else if  housingAnswer.Value = "OTHERHSE"  Then
						    rexParams.HousingLocation.Add ( "(Other)" )    						    
                            ' also add in the other description.
                            Dim housingOtherAnswers as new ArrayList()
				            housingOtherAnswers = questionnaireAnswer.GetAnswers("OtrHouse")   
                            If (answers.Count > 0) Then
				                 Dim housingOtherAnswer As FormsManagement.Answer = housingOtherAnswers(0)
				                 rexParams.HousingLocationOther = housingOtherAnswer.Value
				            End If
						end if
					Next
				End If
				
				answers = questionnaireAnswer.GetAnswers("LabHouse") 
				If (answers.Count > 0) Then
			        Dim housing as FormsManagement.Answer = answers(0)
				    if housing.Value = "Y" then
					    rexParams.HousingOver12 = true
				    else	
					    rexParams.HousingOver12 = false
				    end if
				End If

				Dim labLocation as AnimalsRexParams.LabLocation
		        Dim buildingAnswer As FormsManagement.Answer					   
		        answers = questionnaireAnswer.GetAnswers("locat") 
	            If (answers.Count > 0) Then
	                For Each buildingAnswer In answers
	                    if buildingAnswer.Value <> nothing and buildingAnswer.Value <> string.Empty then
	                            labLocation = new AnimalsRexParams.LabLocation				                        			                    				    
	                            labLocation.BuildingCode =  buildingAnswer.Value				                             
	                            if buildingAnswer.Value = "CNY114" then        				                       
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("CNY114")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If 
	                            else if buildingAnswer.Value = "CNY149" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("CNY149")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "CNY75" then
	                                    buildingAnswer.Value = "75"
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("CNY75")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "BAR" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("BAR")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "BHX" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("BHX")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "BLK" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("BLK")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "BUL" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("BUL")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "COX" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("COX")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "CPZ" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("CPZ")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "EDR" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("EDR")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "ELL" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("Ell")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "FND" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("FND")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "GRB" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("GRB")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "GRJ" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("GRJ")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "SHR" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("SHR")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "THR" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("THR")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "VBK" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("VBK")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "WHT" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("WHT")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            else if buildingAnswer.Value = "WRN" then
	                                    rexParams.LabLocations.Add (labLocation)	
	                                    Dim roomAnswers as new ArrayList()
	                                    roomAnswers = questionnaireAnswer.GetAnswers("WRN")
	                                    If ( roomAnswers.Count > 0) Then
	                                        Dim room as FormsManagement.Answer = roomAnswers(0)
	                                        labLocation.RoomNumber = room.Value				                                        
	                                    End If
	                            end if				                            
	                   end if
	                Next			
		        End If
				
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Potential Pain and Distress
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	  
		    Else If (qV.Questionnaire.Name = "Potential Pain and Distress") Then
				''' CatBNum
				Dim answers as new ArrayList()
				answers = questionnaireAnswer.GetAnswers("CatBNum")
				If (answers.Count > 0) Then
				    Dim catBNum as FormsManagement.Answer = answers(0)
				    Dim i as integer = 0
				    if IsNumeric ( catBNum.Value ) then
						i = FormatNumber(catBNum.Value)
					end if
					rexParams.CatBNum = i
				End If
				
				''' CatCNum
				answers = questionnaireAnswer.GetAnswers("CatCNum")
				If (answers.Count > 0) Then
				    Dim catCNum as FormsManagement.Answer = answers(0)
				    Dim i as integer = 0
				    if IsNumeric ( catCNum.Value ) then
						i = FormatNumber(catCNum.Value)
					end if
					rexParams.CatCNum = i
				End If
				
				''' CatDNum
				answers = questionnaireAnswer.GetAnswers("CatDNum")
				If (answers.Count > 0) Then
				    Dim catDNum as FormsManagement.Answer = answers(0)
				    Dim i as integer = 0
				    if IsNumeric ( catDNum.Value ) then
						i = FormatNumber(catDNum.Value)
					end if
					rexParams.CatDNum = i
				End If
				
				''' CatENum
				answers = questionnaireAnswer.GetAnswers("CatENum")
				If (answers.Count > 0) Then
				    Dim catENum as FormsManagement.Answer = answers(0)
				    Dim i as integer = 0
				    if IsNumeric ( catENum.Value ) then
						i = FormatNumber(catENum.Value)
					end if
					rexParams.CatENum = i
				End If
			
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Tumor Production
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	  
		    Else If (qV.Questionnaire.Name = "Tumor Production") Then
		  
                Dim refCodes as CDS.RefCodes = new CDS.RefCodes(cachePolicy)
                refCodes.Load(connectionString, Nothing)

		        Dim newTumorLine as AnimalsRexParams.TumorCellLine = new AnimalsRexParams.TumorCellLine
				rexParams.TumorCellLines.Add (newTumorLine)
					
                newTumorLine.TumorCellLineName = questionnaireAnswer.GetAnswerValue("Tumor") 
				
				Dim rodOrigin as string = questionnaireAnswer.GetAnswerValue("RodentOrigin") 
				if rodOrigin = "Y" then
	                newTumorLine.RodentOrigin = refCodes.GetRefCode("ANIMCELLRODSOURCE", questionnaireAnswer.GetAnswerValue("RodSource")).Meaning
	                if newTumorLine.RodentOrigin = "Other" then
	                    newTumorLine.OriginOther = questionnaireAnswer.GetAnswerValue("OtrSpecies")
	                end if
				else
	                newTumorLine.RodentOrigin = refCodes.GetRefCode("ANIMCELLNONRODSOURCE", questionnaireAnswer.GetAnswerValue("NonRodSource")).Meaning
	                if newTumorLine.RodentOrigin = "Other" then
	                    newTumorLine.OriginOther = questionnaireAnswer.GetAnswerValue("NonOtrSpecies")
	                end if
				end if

				Dim answerValue as string
				answerValue = questionnaireAnswer.GetAnswerValue("PassRod") 
				If answerValue = "Y" Then
                    newTumorLine.passRodent = true
                Else
                    newTumorLine.passRodent = false
                End If
			
		    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
		    '' Restraint
		    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			Else If (qV.Questionnaire.Name = "Restraint") Then
		
				Dim answers as new ArrayList()
			    answers = questionnaireAnswer.GetAnswers("Conscious") 
			    If (answers.Count > 0) Then
			        Dim conscious as FormsManagement.Answer = answers(0)
			        If conscious.Value = "AWAKE" then
			            ' if CON and PROLONGED, then set another Special Consideration
			            Dim prolongeds  as new ArrayList()
			            prolongeds = questionnaireAnswer.GetAnswers("Duration") 
			            if ( prolongeds.Count > 0 ) then
				            Dim prolonged as FormsManagement.Answer = prolongeds(0)
				            If prolonged.Value = "FOUR" Then
				                rexParams.Considerations.Add ( "Prolonged restraint" )
				            End If
				        end if
				    end If
				End If
				
				answers = questionnaireAnswer.GetAnswers("MechType") 
			    If (answers.Count > 0) Then
			        Dim conscious as FormsManagement.Answer = answers(0)
			        If conscious.Value = "OTR" then
			            rexParams.Considerations.Add ( "Unconventional restraint or behavior" )
				    end If
				End If
			
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Procedures
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			Else If (qV.Questionnaire.Name = "Procedures") Then
			
                Dim refCodes as CDS.RefCodes = new CDS.RefCodes(cachePolicy)
                refCodes.Load(connectionString, Nothing)

			    Dim newProcedure as AnimalsRexParams.Procedure = new AnimalsRexParams.Procedure
				rexParams.Procedures.Add (newProcedure)
				
				Dim answers as new ArrayList()
				answers = questionnaireAnswer.GetAnswers("ProcName")
				
				answers = questionnaireAnswer.GetAnswers("Surgical")
				If ( answers.Count > 0) Then
				    Dim surgType as FormsManagement.Answer = answers(0)
				    If surgType.Value = "Surgical" Then
				        newProcedure.SurgicalType = surgType.Value
                        Dim surgicalAnswers as ArrayList = questionnaireAnswer.GetAnswers("SurgName")
                        if surgicalAnswers.Count > 0 then
                            newProcedure.SurgName = refCodes.GetRefCode("ANIMPROCEDURE", surgicalAnswers(0).Value).Meaning
                        end if
				    Else If surgType.Value = "Non" Then
				        newProcedure.SurgicalType = "Non-Surgical"
                        Dim procedureAnswers as ArrayList = questionnaireAnswer.GetAnswers("ProcName")
                        if procedureAnswers.Count > 0 then
                           newProcedure.SurgName = refCodes.GetRefCode("ANIMPROCEDURE", procedureAnswers(0).Value).Meaning
                        end if
				    End If
				    
				End If 
				
				answers = questionnaireAnswer.GetAnswers("Survival")
				If ( answers.Count > 0) Then
				    Dim survival as FormsManagement.Answer = answers(0)
				    If survival.Value = "Survival" Then
				        newProcedure.Survival = survival.Value
				    Else If survival.Value = "Non" Then
				        newProcedure.Survival = "Non-Survival"
				    End If
				   
				  End If 
					
                 answers = questionnaireAnswer.GetAnswers("Build")
			     If ( answers.Count > 0) Then
			        Dim procBuilding as FormsManagement.Answer = answers(0)
			        If not procBuilding.Value is nothing or procBuilding.Value <> string.empty Then
			           newProcedure.Building = procBuilding.Value
			        End If    				   
			     End If 	
				    
			    answers = questionnaireAnswer.GetAnswers("Room")
			    If ( answers.Count > 0) Then
			        Dim procRoom as FormsManagement.Answer = answers(0)
			        If not procRoom.Value is nothing or procRoom.Value <> string.empty Then
			           newProcedure.Room = procRoom.Value
			        End If    				   
			    End If 
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Tissues
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			Else If (qV.Questionnaire.Name = "Tissue") Then
			
			    Dim newTissue as AnimalsRexParams.Tissue = new AnimalsRexParams.Tissue
				rexParams.Tissues.Add (newTissue)
				
				Dim answers as ArrayList
				answers = questionnaireAnswer.GetAnswers("Type")
				If ( answers.Count > 0) Then
				    Dim tissueType as string = answers(0).value

				    For each questionnaireItem as FormsManagement.QuestionnaireItem in qv.Items
				    	if ( questionnaireItem.Name = "Type") then
				    		for each itemOption as FormsManagement.ItemOption in  questionnaireItem.Options
				    			if (itemOption.OptionValue = tissueType) then
				    				newTissue.Type = itemOption.OptionText
				    				exit for
				    			end if
				    		next
							exit for
						end if
				    Next
				End If 
				
				answers = questionnaireAnswer.GetAnswers("Source")
				If ( answers.Count > 0) Then
				    'If "INT" is selected in question name "Source", then "Protocol" is selected in source column in Rex and the answers given to insight question "ProtNum" populates "Protocol/Vendor Name".  
					newTissue.Source = "Protocol"
					answers = questionnaireAnswer.GetAnswers("ProtNum")
					if (answers.Count > 0) Then
						newTissue.VendorName = answers(0).Value
					End If
				End If 
				
				answers = questionnaireAnswer.GetAnswers("ColSource")
				If ( answers.Count > 0) Then
					'If "COL" is checked in insight question name "ColSource", then "Protocol" is selected in source column in Rex.  The answer given to insight "ColInfo" populates "Protocol Contact" in Rex.
					newTissue.Source = "Protocol"
					answers = questionnaireAnswer.GetAnswers("ColInfo")
					if (answers.Count > 0) Then
						newTissue.ProtocolContact = answers(0).Value
					End If
				End If	
				
				answers = questionnaireAnswer.GetAnswers("BSHSource")
				If ( answers.Count > 0) Then
					'If "BSH" is checked in insight question name "BSHSource, then "Vendor" is selected in source column in Rex.  The answer given to insight "Company" populates "Protocol/Vendor Name" in Rex.
					newTissue.Source = "Vendor"
					answers = questionnaireAnswer.GetAnswers("Company")
					if (answers.Count > 0) Then
						newTissue.VendorName = answers(0).Value
					End If
				End If
				
				answers = questionnaireAnswer.GetAnswers("OtrSource")
				If ( answers.Count > 0) Then
					'If "OTR" is checked in insight question name "OtrSource" then "Vendor" is selected in source column in Rex.  The answer given to insight "Other" populates "Protocol Contact" in Rex.
					newTissue.Source = "Vendor"
					answers = questionnaireAnswer.GetAnswers("Other")
					if (answers.Count > 0) Then
						newTissue.ProtocolContact = answers(0).Value
					End If
				End If	
				
				
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Abstract
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			Else If ( qV.Questionnaire.Name = "Abstract") Then
			
			    Dim answers as new ArrayList()
			    answers = questionnaireAnswer.GetAnswers("Objective")
			    If (answers.Count > 0) Then
			        Dim objective as FormsManagement.Answer = answers(0)
			        
			        'Get the text of the questionnaire
			        Dim questItem As FormsManagement.QuestionnaireItem
					For Each questItem In qV.Items
			            if ( questItem.Name = "Objective") then
			                rexParams.Objective = questItem.HtmlStrippedText
			                rexParams.Objective += vbCrLf 
			                exit for
			            end if
			        Next
			        rexParams.Objective += objective.Value
			    End If
			    
			    answers = questionnaireAnswer.GetAnswers("Significance")
				If (answers.Count > 0) Then
			        Dim significance as FormsManagement.Answer = answers(0)
			        
			        'Get the text of the questionnaire
			        Dim questItem As FormsManagement.QuestionnaireItem
					For Each questItem In qV.Items
			            if ( questItem.Name = "Significance") then
			                rexParams.Significance = questItem.HtmlStrippedText
			                rexParams.Significance += vbCrLf
			                exit for
			            end if
			        Next
			        
			        rexParams.Significance += significance.Value
			    End If
				
				answers = questionnaireAnswer.GetAnswers("SimExp")
			    if (answers.Count > 0 ) Then
			        Dim simExp as FormsManagement.Answer = answers(0)
			        
			        'Get the text of the questionnaire
			        Dim questItem As FormsManagement.QuestionnaireItem
					For Each questItem In qV.Items
			            if ( questItem.Name = "SimExp") then
			                rexParams.SimExp = questItem.HtmlStrippedText
			                rexParams.SimExp += vbCrLf
			                
			                exit for
			            end if
			        Next
			        
			        rexParams.SimExp += simExp.Value
			        
			    End If
			    
			    answers = questionnaireAnswer.GetAnswers("Prior")
			    if ( answers.Count > 0 ) Then
			        Dim prior as FormsManagement.Answer = answers(0)
			        
			        'Get the text of the questionnaire
			        Dim questItem As FormsManagement.QuestionnaireItem
					For Each questItem In qV.Items
			            if ( questItem.Name = "Prior") then
			                rexParams.Prior = questItem.HtmlStrippedText
			                rexParams.Prior += vbCrLf
			                exit for
			            end if
			        Next
			        
			        rexParams.Prior += prior.Value
			    End If
			    
			    answers = questionnaireAnswer.GetAnswers("Endpoints")
			    if ( answers.Count > 0 ) Then
			        Dim endpoints as FormsManagement.Answer = answers(0)
			        
			        'Get the text of the questionnaire
			        Dim questItem As FormsManagement.QuestionnaireItem
					For Each questItem In qV.Items
			            if ( questItem.Name = "Endpoints") then
			                rexParams.Endpoints = questItem.HtmlStrippedText
			                rexParams.Endpoints += vbCrLf
			                exit for
			            end if
			        Next
			        
			        rexParams.Endpoints += endpoints.Value
			    End IF
			    
				
				
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			'' Hazardous Agent Administration and Use
			'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
			Else If (qV.Questionnaire.Name = "Hazardous Agent Administration and Use" ) Then	

                Dim newHazardousAgent as AnimalsRexParams.HazardousAgent = new AnimalsRexParams.HazardousAgent
				rexParams.HazardousAgents.Add (newHazardousAgent)
				
				Dim answers as new ArrayList()
				answers = questionnaireAnswer.GetAnswers("HazardType") 
				If (answers.Count > 0) Then
					Dim hazType as FormsManagement.Answer = answers(0)
					newHazardousAgent.HazardType = hazType.Value
					If (not rexParams.IsAmendment) Then
						select case hazType.Value
							case "Bio"
								Dim bioBoardReview as AnimalsRexParams.BoardReview = new AnimalsRexParams.BoardReview
								rexParams.BoardReviews.Add (bioBoardReview)
								bioBoardReview.Period = 1
								bioBoardReview.DocumentType = "Initial Review"
								bioBoardReview.MailGroupId = 170 'Biosafety MailGroupId
								bioBoardReview.ReviewType = ""
								bioBoardReview.BoardStatus = "Pending"
								overallStatus = Replace(overallStatus, "Pending ", "Pending Biosafety, ")
								bioBoardReview.OverallStatus = overallStatus
								bioBoardReview.CurrentStatus = true
								bioBoardReview.Note = ""
								bioBoardReview.RTFNote = ""
								bioBoardReview.StaffNote = ""
								bioBoardReview.StaffNoteRTF = ""
							case "Rad"
								Dim radBoardReview as AnimalsRexParams.BoardReview = new AnimalsRexParams.BoardReview
								rexParams.BoardReviews.Add (radBoardReview)
								radBoardReview.Period = 1
								radBoardReview.DocumentType = "Initial Review"
								radBoardReview.MailGroupId = 169 'Radiation Safety MailGroupId
								radBoardReview.ReviewType = ""
								radBoardReview.BoardStatus = "Pending"
								overallStatus = Replace(overallStatus, "IACUC", "IACUC, Radiation Safety")
								radBoardReview.OverallStatus = overallStatus
								radBoardReview.CurrentStatus = true
								radBoardReview.Note = ""
								radBoardReview.RTFNote = ""
								radBoardReview.StaffNote = ""
								radBoardReview.StaffNoteRTF = ""
							case "Chem"
								Dim chemBoardReview as AnimalsRexParams.BoardReview = new AnimalsRexParams.BoardReview
								rexParams.BoardReviews.Add (chemBoardReview)
								chemBoardReview.Period = 1
								chemBoardReview.DocumentType = "Initial Review"
								chemBoardReview.MailGroupId = 171 'Safety (Chemical) MailGroupId
								chemBoardReview.ReviewType = ""
								chemBoardReview.BoardStatus = "Pending"
								if (InStr(overallStatus, "Radiation Safety") > 0)
									overallStatus = Replace(overallStatus, "Radiation Safety", "Radiation Safety, Safety")
								else
									overallStatus = Replace(overallStatus, "IACUC", "IACUC, Safety")
								end if
								chemBoardReview.OverallStatus = overallStatus
								chemBoardReview.CurrentStatus = true
								chemBoardReview.Note = ""
								chemBoardReview.RTFNote = ""
								chemBoardReview.StaffNote = ""
								chemBoardReview.StaffNoteRTF = ""
							
							
						end select
					End If
				End If
				
				answers = questionnaireAnswer.GetAnswers("Building") 
				If (answers.Count > 0) Then
				    Dim buildingAnswer As FormsManagement.Answer
					For Each buildingAnswer In answers
					    if  buildingAnswer.Value = "CNY114"  Then
						    newHazardousAgent.Building.Add ( "114" )	
						else if  buildingAnswer.Value = "CNY149"  Then
						    newHazardousAgent.Building.Add ( "149" )	
						else if  buildingAnswer.Value = "CNY75"  Then
						    newHazardousAgent.Building.Add ( "75" )	
						else if  buildingAnswer.Value <> ""  Then
						    newHazardousAgent.Building.Add ( buildingAnswer.Value )	
						end if			    
				    Next
				End If
				
				answers = questionnaireAnswer.GetAnswers("Room")
				If (answers.Count > 0) Then
				    Dim roomAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Room = roomAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Dose")
				If (answers.Count > 0) Then
				    Dim doseAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Dose = doseAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Route")
				If (answers.Count > 0) Then
				    Dim routeAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Route = routeAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("TotalDoses")
				If (answers.Count > 0) Then
				    Dim totalDosesAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.TotalDoses = totalDosesAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Duration")
				If (answers.Count > 0) Then
				    Dim durationAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Duration = durationAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Manipulations")
				If (answers.Count > 0) Then
				    Dim manipulationsAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Manipulations = manipulationsAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Isotope")
				If (answers.Count > 0) Then
				    Dim isotopeAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Isotope = isotopeAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("PermitNum")
				If (answers.Count > 0) Then
				    Dim permitNumAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.PermitNum = permitNumAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("PermitName")
				If (answers.Count > 0) Then
				    Dim permitNameAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.PermitName = permitNameAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Frequency")
				If (answers.Count > 0) Then
				    Dim frequencyAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Frequency = frequencyAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Chem")
				If (answers.Count > 0) Then
				    Dim chemAnswer As FormsManagement.Answer = answers(0)
				    newHazardousAgent.Chemical = chemAnswer.Value
				End If
				
				answers = questionnaireAnswer.GetAnswers("Bio")
				If (answers.Count > 0) Then
				    Dim bioAnswer as FormsManagement.Answer = answers(0)
				    newHazardousAgent.BioAgent = bioAnswer.Value
				End If

			'Else If (qV.Questionnaire.Name = "Tissue") Then
				'Dim answers as new ArrayList()
				'answers = questionnaireAnswer.GetAnswers("Type")
				'If (answers.Count > 0) Then
					'Dim tissueType as AnimalsRexParams.TissueType = new AnimalsRexParams.TissueType
					'rexParams.TissueTypes.Add (tissueType )
				   'rexParams.
				'End If

			End If
		        

		Next
			
    end sub	

    sub AddArrayListItem( byval qa as FormsManagement.QuestionnaireAnswer, byval answerName as string, byval answerValue as string, byref list as ArrayList, byval itemToAdd as string )
        Dim answers as ArrayList = qa.GetAnswers(answerName)
        if ( answers.Count > 0 ) then
            if ( answers(0).Value = answerValue ) then
                list.Add( itemToAdd )
            end if
        end if
    end sub
end module